
#include "pch.h"
#include "mono/System.h"
#include "mono/Converter.h"


int main()
{
    ztclog::pushFunction([](const ztclog::Line &line)
                         { std::cout << line.m_Text << std::endl; });

    auto system = std::make_shared<mono::System>("the mono domain");
    if (!system->LoadCS("hello.dll"))
    {
        ztclog::info("faield load cs");
        return 1;
    }
    auto behivor = system->GetCS("hello.dll");
    // bool res = behivor->LoadClazz("", "TextLine+Type");
    // return 1;

    auto clazz = behivor->GetClazz("", "ExampleProgram");

    auto obj = clazz->NewObject();
    {

        auto method = clazz->GetMethod("dot2", 2);
        mono::Args args;
        float a1 = 10.3f;
        float b2 = 20.0f;

        args.PushArg(a1);
        args.PushArg(b2);

        float res;
        bool flag = obj->Invoke2<float>(method.get(), args, res);
        ztclog::info("res2 is %f", res);
    }

    {
        auto method = clazz->GetMethod("test1", 0);
        obj->Invoke(method.get(), {});
        obj->Invoke(method.get(), {});
    }

    {
        auto method = clazz->GetMethod("Add", 2);
        mono::Args args;
        int a = 22, b = 222;
        args.Push(&a);
        args.Push(&b);

        int sum = 0;
        bool res = method->Invoke2<int>(args, sum);

        ztclog::info("result sum is %d", sum);
    }

    return 0;
};

